package com.slipper.system.restore.service;

import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;

import com.slipper.system.restore.dao.RestoreDao;
import com.slipper.system.restore.bo.RestoreBO;

import com.slipper.core.transaction.ReadTransactional;
import com.slipper.core.transaction.WriteTransactional;
import com.slipper.util.Tool;
import com.slipper.util.UUID;

import java.util.List;

@Service
@ReadTransactional
public class RestoreService {
    @Resource
    private RestoreDao restoreDao;
    
    public RestoreBO queryLast() {
        List<RestoreBO> restoreList = restoreDao.queryLast();
        return restoreList.isEmpty() ? null : restoreList.getFirst();
    }

    @WriteTransactional
    public int save(RestoreBO bo) {
        if (Tool.isNotBlank(bo.getId())) {
            return restoreDao.update(bo);
        } else {
            bo.setId(UUID.getUUID());
            bo.setCreateTime(System.currentTimeMillis());
            return restoreDao.insert(bo);
        }
    }
    
    @WriteTransactional
    public int delete(RestoreBO bo) {
        return restoreDao.delete(bo);
    }
}
